//
//  TradeOrderUserCenterOneCell.swift
//  Exchange
//
//  Created by rui on 2018/5/22.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class TradeOrderUserCenterOneCell: UITableViewCell {

    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var payType: UIImageView!
    @IBOutlet weak var limitPrice: UILabel!
    @IBOutlet weak var buy: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.selectionStyle = .none
        self.buy.layer.cornerRadius = 3
        self.buy.layer.masksToBounds = true
        let view = UIView(frame: self.bounds)
        view.autoresizingMask = [.flexibleWidth,.flexibleHeight]
        self.selectedBackgroundView = UIView(frame: self.bounds)
        self.selectedBackgroundView?.themeBackground = ThemeManager.ThemeColorKeys.selectTabColor
    }
 
    @IBAction func buyClick(_ sender: UIButton) {
        
    }
    
    func configer(model: AdvertisingListModel) {
        if model.paymentMethod == 2 {
            self.payType.image = #imageLiteral(resourceName: "unionPay")
        }else {
            self.payType.image = #imageLiteral(resourceName: "aliPay")
        }
        
        let currency = model.currency ?? ""
        self.price.text = "0.00 \(currency)"
        if let exTick = AppContext.default.exTickData {
            let datas = exTick.filter { (data) -> Bool in
                return data["money"] as? String == currency
            }
            if let data = datas.first,let symbols = data["symbols"] as? [String:Double]  {
                if var exPrice = symbols[(model.moneyType ?? "")] {
                    exPrice = exPrice + exPrice * (model.premium ?? 0) / 100
                    self.price.text = String(format: "%0.2lf %@", exPrice,currency)
                }
            }
        }
        let lowest = model.limitLowerMoney ?? 0
        let high = model.limitUpperMoney ?? 0
        self.limitPrice.text = String(format: "%0.2lf~%0.2lf %@", lowest,high,currency)
        var moneyType = model.moneyType ?? ""
        if AppCacheInfo.default.isEnlish {
            moneyType = " " + moneyType
        }
        if model.type == 0 {
            self.buy.setTitle(kText("出售") + "\(moneyType)", for: .normal)
        }else {
            self.buy.setTitle(kText("购买") + "\(moneyType)", for: .normal)
        }
    }
    
}
